{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "#coding:utf-8\n",
    "from aip import AipNlp\n",
    "\n",
    "APP_ID = '15270666'\n",
    "API_KEY = '3CC8biyG2E2etjhLEcgGGTxP'\n",
    "SECRET_KEY = 'Fwq70qbSpwKFuRMqNFTQGqmN1a3qKxpH'\n",
    "client = AipNlp(APP_ID, API_KEY, SECRET_KEY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "Special = ['乐迪','小爱','多多','酷飞','米莉','淘淘','金刚','酷雷','小青','包警长','胡须爷爷',\n",
    "      '卡文','卡尔叔叔','皮皮','大鹏','金宝','安琪','豆豆','圆圆']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "def findName(txt):\n",
    "    result = client.lexer(txt)\n",
    "    name = []\n",
    "    for i in range (len(result['items'])):\n",
    "        if (result['items'][i]['ne'] == 'PER')and(result['items'][i]['item'] not in Special) \\\n",
    "            and(result['items'][i]['item'] not in name):\n",
    "            name.append(result['items'][i]['item'])\n",
    "    return name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "def writeTxt(txt):\n",
    "    f = open('information/人物名称.txt','a')\n",
    "    f.write(txt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [],
   "source": [
    "i = 0\n",
    "with open('information/第三季.txt','r') as f:\n",
    "    for line in f:\n",
    "        if i%2 == 1:\n",
    "            nameAll = findName(line)\n",
    "            if len(nameAll) > 0:\n",
    "                writeTxt(nameAll[0]+'\\n')\n",
    "        i += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
